package com.yanqu.road.web.controller.game.forbid;

import com.yanqu.road.entity.admin.AdminResult;
import com.yanqu.road.entity.player.UserInfo;
import com.yanqu.road.logic.bussiness.player.UserBussiness;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.player.GamePlayerMgr;

/**
 * @Author : Cxp
 * @Time : 2025-02-17
 * @Description : 禁言
 */

public class BanSpeak extends BanBase {

    public BanSpeak(long userId, long endTime) {
        super(userId, endTime);
    }

    @Override
    AdminResult banAction() {
        GamePlayer onlinePlayer = GamePlayerMgr.getOnlinePlayer(userId);
        if (onlinePlayer != null) {
            UserInfo uInfo = onlinePlayer.getUserInfo();
            uInfo.setForbiddenSpeakEndTime(endTime);
        } else {
            UserBussiness.updateForbidSpeak(userId, endTime);
        }

        AdminResult result = getBanResult(); // 仅记录
        if (result != null) {
            return result;
        }

        return AdminResult.defaultInstance();
    }

    @Override
    AdminResult unbanAction() {
        GamePlayer onlinePlayer = GamePlayerMgr.getOnlinePlayer(userId);
        if (onlinePlayer != null) {
            UserInfo uInfo = onlinePlayer.getUserInfo();
            uInfo.setForbiddenSpeakEndTime(0);
        } else {
            UserBussiness.updateForbidSpeak(userId, 0);
        }

        AdminResult result = getUnbanResult(); // 仅记录
        if (result != null) {
            return result;
        }

        return AdminResult.defaultInstance();
    }
}